<?php

class UrlGenerator
{
	/**
	 * @var string
	 */
	private $url;
	
	/**
	 * @var array
	 */
	private $parameters = array();

	function __construct($url)
	{
		$this->url = $url;
	}

	/**
	 * @return string
	 */
	public function getUrl()
	{
		return $this->url;
	}

	/**
	 * @param string $url
	 */
	public function setUrl($url)
	{
		$this->url = $url;
	}

	/**
	 * @param string $name
	 * @param string $value
	 */
	public function setParameter($name, $value)
	{
		$this->parameters[$name] = $value;
	}

	/**
	 * @return string
	 */
	public function toString()
	{
		$query_string = '';
		foreach ($this->parameters as $key => $value)
		{
			$query_string .= (($query_string == '')? '?' : '&amp;');
			$query_string .= $key . '=';
			$query_string .= urlencode($value);
		}

		return $this->url.$query_string;
	}
}
?>
